#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

vector<int> nextGreaterElements(vector<int>& nums) {
    int n = nums.size();
    vector<int> v;
    for (int i = 0; i < n; i++)
    {
        for (int j = (i + 1) % n; j < n; j++)
        {
            if (nums[j] > nums[i])
            {
                v.push_back(nums[j]);
                break;
            }
            if (i+1 == j)
            {
                v.push_back(-1);
                break;
            }
        }
    }
    return v;
}

int main()
{
    vector<int> test = {1,2,3,4,5};
    vector<int> ret = nextGreaterElements(test);
    for (auto e : ret)
    {
        cout << e << " ";
    }
        
    return 0;
}